/**
 * Copyright (c) 2011 ~ 2014 Deepin, Inc.
 *               2013 ~ 2014 jouyouyun
 *
 * Author:      jouyouyun <jouyouwen717@gmail.com>
 * Maintainer:  jouyouyun <jouyouwen717@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 **/

package main

import (
	"fmt"
	"io/ioutil"
	"strings"
)

type langInfo struct {
	lang           string
	env            string
	locale         string
	fallbackLocale string
	langCode       string
	conutryCode    string
	langList       string
	consoleData    string
}

func getLangInfoList() []langInfo {
	list := []langInfo{}

	contents, err := ioutil.ReadFile("list")
	if err != nil {
		fmt.Println(err)
		return list
	}

	lines := strings.Split(string(contents), "\n")
	for _, line := range lines {
		strs := strings.Split(line, ";")
		if len(strs) < 8 {
			continue
		}

		info := langInfo{}
		info.lang = strs[0]
		info.env = strs[1]
		info.locale = strs[2]
		info.fallbackLocale = strs[3]
		info.langCode = strs[4]
		info.conutryCode = strs[5]
		info.langList = strs[6]
		info.consoleData = strs[7]

		list = append(list, info)
	}

	return list
}

func searchLangInfo(key string) (langInfo, bool) {
	list := getLangInfoList()

	for _, info := range list {
		if info.locale == key {
			return info, true
		}
	}

	return langInfo{}, false
}

func main() {
	for _, v := range localeList {
		fmt.Printf("%s: ", v)
		info, ok := searchLangInfo(v)
		if ok {
			fmt.Printf("%s %s %s", info.lang,
				info.fallbackLocale, info.langList)
		}
		fmt.Printf("\n")
	}
}
